<?php namespace web\admin\controller;
/** .-------------------------------------------------------------------
 * |  Software: [HDPHP framework]
 * |      Site: www.hdphp.com
 * |-------------------------------------------------------------------
 * |    Author: 向军 <2300071698@qq.com>
 * |    WeChat: aihoudun
 * | Copyright (c) 2012-2019, www.houdunwang.com. All Rights Reserved.
 * '-------------------------------------------------------------------*/

class Entry extends Common{
	private $db;
	public function __construct(){
		parent::__construct();
//		实例化数据库表
		$this->db=new \system\model\User;
	}
	
	
	
	//首页
	public function index() {
		View::make();
	}
	
//	后台信息
	public function welcome(){
		View::make();
	}
	
	public function changePwd(){
		if(IS_POST){
			$oldPwd=Q('post.oldPwd','','md5');
			$newPwd1=Q('post.newPwd1','','md5');
			$newPwd2=Q('post.newPwd2','','md5');
//			判断两次密码是否一致
			if($newPwd1!=$newPwd2){
				message('两次输入密码不一致，请重新输入');
			}
//			判断原密码是否一致
			$data=$this->db->where('uid',$_SESSION['id'])->first();
			if($oldPwd!=$data['password']){
				message('原密码验证错误，请重新输入');
			}
//			写入数据库
			$re=$this->db->where('uid',$data['uid'])->update(array('password'=>$newPwd1));
			if(!$re){
				message('修改失败，请重新操作');
			}
//			3.将session清除
			session_unset();
			session_destroy();
//			修改成功
			$url=U('login/index');
			$str=<<<str
<script type="text/javascript">
		alert('修改成功');
		parent.location.href="{$url}";
	</script>
str;
			echo $str;die;
		}
		View::make();
	}
//	退出登录
	public function out(){
//			将session清除
			session_unset();
			session_destroy();
			$url=U('Login/index');
			$str=<<<str
	<script type="text/javascript">
		alert('退出成功');
		parent.location.href="{$url}";
	</script>		
str;
			echo $str;die;
	}
	
	public function webset(){
		View::make();
	}
	
}